<!doctype html>

<html>

<head>

    <meta charset="utf-8">

    <title>收货地址-{$tpshop_config['shop_info_store_title']}</title>

    <meta http-equiv="keywords" content="{$tpshop_config['shop_info_store_keyword']}" />
    <meta name="description" content="{$tpshop_config['shop_info_store_desc']}" />
    <script src="__PUBLIC__/js/jquery-1.10.2.min.js"></script>
	<script src="__PUBLIC__/js/layer/layer-min.js"></script><!--弹窗js 参考文档 http://layer.layui.com/-->

</head>

<style type="text/css">

.wi80-BFB{width:90%;font-size:13px;}

.wi40-BFB{width:40%}

.seauii{ padding:7px 10px; margin-right:10px}

.he110{ height:110px}

.di-bl{ display:inherit}
.box-content{display: flex;}
.box-content div{padding:15px;height: 230px;font-size: 12px}
.box-content h3{font-weight: normal;text-align: center;}
.box-content .wait-box,.box-content .fail-box{flex:1;}
.box-content .wait-cont{border:1px solid #ccc;border-radius: 3px;overflow-y:scroll; }
.box-content .fail-cont{border:1px solid #ccc;border-radius: 3px;overflow-y:scroll; }
.box-content .btn-img{width:50px;}
.box-content li{list-style: none;}
.fail-cont{color:#red;}
.all_send_box li{line-height: 20px}
</style>

<body>

<div class="adderss-add">

    <div class="ner-reac ol_box_4" style="visibility: visible; position: fixed; z-index: 500; width: 100%; height:100%">

        <div class="box-ct">

            <div class="box-header">

                <!-- <a href="" class="box-close"></a> -->

            </div>

            <form action="{:U('Admin/User/doSendwxMessage')}" method="post" onSubmit="return checkForm()">
                <input name="call_back" type="hidden" value="call_back" />
                <input name="type" type="hidden" value="{$users.send_area}" />
                <input name="link" type="hidden" value="{$users.link}" />
                <input name="content" type="hidden" value="{$users.content}" />
                
                <div class="box-content">
                    <if condition="$users['send_area'] eq 0">
                    <div class="wait-box">
                        <h3>待发送用户列表</h3>
                        <div class="wait-cont"></div>
                    </div>
                    <div style="padding-top:100px"><img src="__PUBLIC__/images/l_arrow.png" width="40" class="l_arrow"><br/><img src="__PUBLIC__/images/r_arrow.png" width="40" class="r_arrow"></div>
                    <div class="fail-box">
                        <h3>失败列表</h3>
                        <div class="fail-cont" contenteditable="true">
                            <volist name="faillist" id="vo">
                             <li data="fail-li">{$vo.to_member|shownickname=###}</li>
                            </volist>
                        </div>
                    </div>
                    <else/>
                    <div class="all_send_box">
                        <li><span>待发送人群：</span><span>全体会员</span></li>
                        <li><span>当前发送：</span><span>全体会员</span></li>
                        <li><span>已成功：<font>0</font></span></li>
                        <li><span>已失败：<font>0</font></span></li>
                    </div>
                    </if>
                </div>
               
                 <div style="display:flex">
                 <div class="msg_res" style="flex:1"></div>
                 <div style="flex:1;text-align:right;padding-right:15px;position:absolute;bottom:20px;right:10px"><input type="button" style="padding: 4px 16px;cursor: pointer;" value="确认发送" onclick="sendwxxi()"/></div></div>
            </form>

        </div>

    </div>

</div>

<script src="__PUBLIC__/js/global.js"></script>

<script src="__PUBLIC__/js/pc_common.js"></script>



<script>
var base = new Base64();
var waitcont='{$users.user_list}';
if(waitcont){
 waitcont=base.decode(waitcont);
 var arrs=waitcont.replace(/，/g,',').replace(/,$/gi,"").split(',');
 var wait_str="";
 for(var i=0;i<arrs.length;i++){
     wait_str+='<li class="a'+i+'" data="wait-li">'+arrs[i]+'</li>';
 }
 $('.wait-cont').html(wait_str);
}


$('.fail-cont').on('dblclick','li',function(){
    var data=$(this).attr('data');
    if(data=="fail-li"){
        $('.wait-cont').append('<li>'+$(this).text()+'</li>');
        $(this).remove();
    }
})
$('.wait-cont').on('dblclick','li',function(){
    var data=$(this).attr('data');
    if(data!="wait-li"){
        $('.fail-cont').append('<li data="fail-li">'+$(this).text()+'</li>');
        $(this).remove();
    }
})
$('.l_arrow').click(function(){
    var cont=$.trim($('.fail-cont').html());
    if(cont!=''){
        $('.wait-cont').append(cont);
        $('.fail-cont').html('');
    }
   
})
$('.r_arrow').click(function(){
    var cont=$.trim($('.wait-cont').html());
    if(cont!=''){
        $('.fail-cont').append(cont);
        $('.wait-cont').html('');
    }
})
var k=0;
function sendwxxi(){
    var viplist=iGetInnerText($('.wait-cont').html().replace(/<\/li><li/g,',<li').replace(/<[^>]+>/g,""));

    if(viplist==""){
        alert('待发用户为空');
        return false;
    }
    $('.msg_res').html('成功：<span class="succ">0</span>失败：<span class="fail">0</span>');
    var vips=viplist.split(',');
    var type=$('input[name="type"]').val();
    var url=$('input[name="link"]').val();
    var tpltext=$('input[name="content"]').val();
    ajax_post(vips,tpltext,type,url,k);
   
}

function ajax_post(vips,tpltext,type,url,k){
    if(vips[k].indexOf(':')>-1){
        var userid=$.trim(vips[k].split(':')[0]);
        var mobile='u'+userid;
    }else{
        var mobile=$.trim(vips[k]);
    }
    $('.a'+k).animate({'font-size':'14px'});


    $.post("{:U('Admin/User/doSendwxMessage')}",{mobile:mobile,tpltext:tpltext,type:type,url:url,k:k,wid:'{$wid}'},
        function(res){
           var result=eval('(' + res + ')');
           if(result.errmsg=="ok"){
               var succ=parseInt($('.succ').text());
               succ++;
               $('.succ').text(succ);
           }else{
               var fail=parseInt($('.fail').text());
               fail++;
               $('.fail').text(fail);
               $('.fail-cont').append('<li data="fail-li">'+mobile+'</li>');
           }
           $('.a'+k).fadeOut();
           k++;
           if(k<vips.length){
               ajax_post(vips,tpltext,type,url,k);
           }else{
               $('.loading').remove();
               var succnum=parseInt($('.succ').text());
               var failnum=parseInt($('.fail').text());
               $.post("{:U('Admin/User/count_wxmessage')}",{succ:succnum,fail:failnum,wid:'{$wid}'},function(ress){
                    parent.update_res('{$wid}',succnum,failnum,ress);
                    $('.wait-cont').html('');
               }) 
           }  
       })
}
function animate_send(str){
    var viplist=iGetInnerText($('.viplist').text())+',';
    viplist=viplist.replace(str+',','');
}
function iGetInnerText(testStr) {
        var resultStr = testStr.replace(/\ +/g, ""); //去掉空格
        resultStr = testStr.replace(/[ ]/g, "");    //去掉空格
        resultStr = testStr.replace(/[\r\n]/g, ""); //去掉回车换行
        return resultStr;
    }

    function Base64() { 
      
     // private property 
     _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 
      
     // public method for encoding 
     this.encode = function (input) { 
      var output = ""; 
      var chr1, chr2, chr3, enc1, enc2, enc3, enc4; 
      var i = 0; 
      input = _utf8_encode(input); 
      while (i < input.length) { 
       chr1 = input.charCodeAt(i++); 
       chr2 = input.charCodeAt(i++); 
       chr3 = input.charCodeAt(i++); 
       enc1 = chr1 >> 2; 
       enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 
       enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 
       enc4 = chr3 & 63; 
       if (isNaN(chr2)) { 
        enc3 = enc4 = 64; 
       } else if (isNaN(chr3)) { 
        enc4 = 64; 
       } 
       output = output + 
       _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + 
       _keyStr.charAt(enc3) + _keyStr.charAt(enc4); 
      } 
      return output; 
     } 
      
     // public method for decoding 
     this.decode = function (input) { 
      var output = ""; 
      var chr1, chr2, chr3; 
      var enc1, enc2, enc3, enc4; 
      var i = 0; 
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 
      while (i < input.length) { 
       enc1 = _keyStr.indexOf(input.charAt(i++)); 
       enc2 = _keyStr.indexOf(input.charAt(i++)); 
       enc3 = _keyStr.indexOf(input.charAt(i++)); 
       enc4 = _keyStr.indexOf(input.charAt(i++)); 
       chr1 = (enc1 << 2) | (enc2 >> 4); 
       chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 
       chr3 = ((enc3 & 3) << 6) | enc4; 
       output = output + String.fromCharCode(chr1); 
       if (enc3 != 64) { 
        output = output + String.fromCharCode(chr2); 
       } 
       if (enc4 != 64) { 
        output = output + String.fromCharCode(chr3); 
       } 
      } 
      output = _utf8_decode(output); 
      return output; 
     } 
      
     // private method for UTF-8 encoding 
     _utf8_encode = function (string) { 
      string = string.replace(/\r\n/g,"\n"); 
      var utftext = ""; 
      for (var n = 0; n < string.length; n++) { 
       var c = string.charCodeAt(n); 
       if (c < 128) { 
        utftext += String.fromCharCode(c); 
       } else if((c > 127) && (c < 2048)) { 
        utftext += String.fromCharCode((c >> 6) | 192); 
        utftext += String.fromCharCode((c & 63) | 128); 
       } else { 
        utftext += String.fromCharCode((c >> 12) | 224); 
        utftext += String.fromCharCode(((c >> 6) & 63) | 128); 
        utftext += String.fromCharCode((c & 63) | 128); 
       } 
      
      } 
      return utftext; 
     } 
      
     // private method for UTF-8 decoding 
     _utf8_decode = function (utftext) { 
      var string = ""; 
      var i = 0; 
      var c = c1 = c2 = 0; 
      while ( i < utftext.length ) { 
       c = utftext.charCodeAt(i); 
       if (c < 128) { 
        string += String.fromCharCode(c); 
        i++; 
       } else if((c > 191) && (c < 224)) { 
        c2 = utftext.charCodeAt(i+1); 
        string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); 
        i += 2; 
       } else { 
        c2 = utftext.charCodeAt(i+1); 
        c3 = utftext.charCodeAt(i+2); 
        string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); 
        i += 3; 
       } 
      } 
      return string; 
     } 
    } 
</script>

</body>

</html>

